var wordBreak = function(s, wordDict) {
  const len = s.length;

  const dp = new Array(len + 1).fill(0);
  dp[0] = 1;
  
  // 考虑背包结果顺序---先背包再物品
  for (let i = 0; i <= len; i++) {
    for (let j = 0; j < wordDict.length; j++) {
      let cur = wordDict[j];
      if (i >= cur.length) {
        if (dp[i - cur.length] === 1 && cur === s.slice(i - cur.length, i)) {
          dp[i] = 1;
        }
      }
    }
  }
  return dp[len] === 1;
}

const s = "leetcode", wordDict = ["leet", "code"];
console.log(wordBreak(s,wordDict))